#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <gl\glew.h>
#include <gl\freeglut.h>
#include <iostream>
#include <vector>
#include <windows.h>

#include <stdio.h>

#include <conio.h>

using namespace std;


int height = 500;
int width = 500;
//int const pixs = 250000;
//Vertex verts[pixs];

GLuint vertexbuffer;

int x_clicked;
int y_clicked;
int dir = 1;


static const GLfloat g_vertex_buffer_data[] = {
   -1.0f, -1.0f, 0.0f,
   1.0f, -1.0f, 0.0f,
   0.0f,  1.0f, 0.0f,
};





void display(void){

	glViewport(0, 0, width, height);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0, width, 0, height, -1, 1);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);	

	glLoadIdentity();
	// 1rst attribute buffer : vertices
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
   0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
   3,                  // size
   GL_FLOAT,           // type
   GL_FALSE,           // normalized?
   0,                  // stride
   (void*)0            // array buffer offset
);
 
// Draw the triangle !
glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
 
glDisableVertexAttribArray(0);
	glFlush(); 

	
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);

    glutPostRedisplay();

	return;
}


//void clicker(int button, int state, int x, int y) {
//    if (state == GLUT_DOWN)
//	{
//		x_clicked = x; 
//		y_clicked = y;
//		click = true;
//	}
//}

int main(int argc, char **argv)
{	
	
	glutInit(&argc, argv); // Initialize GLUT  
	glutInitDisplayMode (GLUT_SINGLE); // Set up a basic display buffer (only single buffered for now)  
	glutInitWindowSize (width, height); // Set the width and height of the window
	glutInitWindowPosition (100, 100); // Set the position of the window
	glutCreateWindow ("Point Cloud"); // Set the title for the window  
	GLuint VertexArrayID;
	glGenVertexArrays(1, &VertexArrayID);
	glBindVertexArray(VertexArrayID);
	
	glGenBuffers(1, &vertexbuffer);
	glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
	glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);



	glutDisplayFunc(display);  // Tell GLUT to use the method "display" for rendering  

	glutMainLoop(); // Enter GLUT's main loop  

	return 0;
}